package cn.ddiancan.xddcloud.psc.flow.entity;

import java.io.Serializable;

import cn.ddiancan.xddcloud.psc.flow.constants.FlowConstants;
import cn.ddiancan.xddcloud.psc.flow.engine.cache.ProcessModelCache;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
 * 扩展流程实例实体类
 * @since 1.0
 */
@Getter
@Setter
@ToString
public class XddExtInstance implements ProcessModelCache, Serializable {

    /**
     * 主键ID
     */
    private Long id;

    /**
     * 租户ID
     */
    private String tenantId;

    /**
     * 流程定义ID
     */
    private Long processId;

    /**
     * 流程定义名称（冗余业务直接可用）
     */
    protected String processName;

    /**
     * 流程定义类型（冗余业务直接可用）
     */
    protected String processType;

    /**
     * 流程模型定义JSON内容
     * 在发起的时候拷贝自流程定义模型内容，用于记录当前实例节点的动态改变。

     */
    private String modelContent;

    public static XddExtInstance of(XddInstance flwInstance, XddProcess flwProcess) {
        XddExtInstance ext = new XddExtInstance();
        ext.id = flwInstance.getId();
        ext.tenantId = flwInstance.getTenantId();
        ext.processId = flwInstance.getProcessId();
        ext.processName = flwProcess.getProcessName();
        ext.processType = flwProcess.getProcessType();
        ext.modelContent = flwProcess.getModelContent();
        return ext;
    }

    @Override
    public String modelCacheKey() {
        return FlowConstants.processInstanceCacheKey + this.id;
    }
}
